<template>
	<view class="form">
		<uni-forms ref="form" :rules="{}">
			<uni-forms-item label="电话" name="">
				<uni-easyinput v-model="data.telephone" placeholder="" />
			</uni-forms-item>
			<uni-forms-item label="密码" name="">
				<uni-easyinput v-model="data.password" type="password" placeholder="" />
			</uni-forms-item>
			<uni-forms-item label="" name="">
				<button type="primary" @click="login">登录</button>
			</uni-forms-item>
		</uni-forms>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				data: {
					"password": "123",
					"telephone": "12345678901"
				}
			}
		},
		methods: {
			login() {
				// 获取用户输入的数据，

				// 发起网络访问的请求
				uni.request({
					url: 'http://localhost:8090/foodapp/user/login',
					method: 'POST',
					data: this.data,
					success: res => {
						if (res.data.success) {
							// 处理网络API返回的数据
							// 保存用户信息到本地存储
							let userinfo = res.data.data
							uni.setStorageSync("userinfo", userinfo)
							// 重新跳转到my页码
							uni.switchTab({
								url: '/pages/my/my'
							})
						} else {

						}
					},
					fail: () => {},
					complete: () => {}
				});

			}
		}
	}
</script>

<style>
	.form {
		padding: 10px;
	}
</style>